<?
	$globe_prefix = array('0817', '0905','0906','0915','0916','0917','09178','0926','0927','0935','0936','0937','0994','0996','0997');
	$smart_prefix = array('0813','0907','0908','0909','0910','0912','0918','0919','0920','0921','0928','0929','0930','0938','0939','0947','0948','0949', '0989','0998','0999');
	$tnt_prefix = array('0907','0908','0909','0910','0912','0919','0920','0921','0928','0929','0930','0938','0939','0946','0948','0949','0989');
	$sun_prefix = array('0922','0923','0925','0932','0933','0934','0942','0943');
	$touch_prefix = array('0905','0906','0915','0916','0926','0927','0935','0936','0937','0996','0997');
	$red_prefix = array('0930','0920','0938','0939');
?>
<div class="row">
	<div class="panel callout"><h6>Phonebook</h6></div>
	<?if(isset($system_message))  echo $system_message;?>
	<form action="<?=site_url(array('phonebook', 'student_phonebook')); ?>" id="search_phonebook" method="POST">
		<div class="row">
			<div class="large-12 columns">
				<div class="row collapse">
					<div class="small-10 columns">
						<input type="text" placeholder="Enter name or number..." name="search_param" id="search_param">
					</div>
					<div class="small-2 columns">
						<input type="submit" class="button secondary prefix" name="search_btn" id="search_btn" value="Search"/>
					</div>
				</div>
			</div>
		</div>
	</form>
	
	<?if(!empty($search_results)):?>
		<fieldset>
			<legend>Search Results for '<?=$search_param;?>'</legend>
			<table>
				<thead>
					<tr>
						<th></th>
						<th>Mother</th>
						<th>Number</th>
						<th>Carrier</th>
						<th>Father</th>
						<th>Number</th>
						<th>Carrier</th>
					</tr>
				</thead>
				<tbody>
					<?foreach($search_results AS $s):?>
						<tr>
							<td><?=strtoupper($s->lastname) . ', ' . ucfirst($s->firstname) . ' ' . ucfirst($s->middlename);?></td>
							<td><?=ucwords($s->mother_lname) . ', ' . ucfirst($s->mothername) . ' ' . ucfirst($s->mother_mname);?></td>
							<td><?=$s->mother_contact_no;?></td>
							<td>
							<?$carrier_array = array();
								$prefix = substr($s->mother_contact_no, 0, 4);
								if(in_array($prefix, $globe_prefix))
								{
									array_push($carrier_array, 'Globe');
								}
								if(in_array($prefix, $smart_prefix))
								{
									array_push($carrier_array, 'Smart');
								}
								if(in_array($prefix, $tnt_prefix))
								{
									array_push($carrier_array, 'Talk N Text');
								}
								if(in_array($prefix, $sun_prefix))
								{
									array_push($carrier_array, 'Sun');
								}
								if(in_array($prefix, $touch_prefix))
								{
									array_push($carrier_array, 'Touch Mobile');
								}
								if(in_array($prefix, $red_prefix))
								{
									array_push($carrier_array, 'Red');
								}
								
								for($x = 0; $x<count($carrier_array); $x++)
								{
									echo($carrier_array[$x] . ', ');
								}
							?>
							</td>
							<td><?=ucwords($s->father_lname) . ', ' . ucfirst($s->fathername) . ' ' . ucfirst($s->father_mname);?></td>
							<td><?=$s->father_contact_no;?></td>
							<td><?
								$carrier_array = array();
								$prefix = substr($s->father_contact_no, 0, 4);
								if(in_array($prefix, $globe_prefix))
								{
									array_push($carrier_array, 'Globe');
								}
								if(in_array($prefix, $smart_prefix))
								{
									array_push($carrier_array, 'Smart');
								}
								if(in_array($prefix, $tnt_prefix))
								{
									array_push($carrier_array, 'Talk N Text');
								}
								if(in_array($prefix, $sun_prefix))
								{
									array_push($carrier_array, 'Sun');
								}
								if(in_array($prefix, $touch_prefix))
								{
									array_push($carrier_array, 'Touch Mobile');
								}
								if(in_array($prefix, $red_prefix))
								{
									array_push($carrier_array, 'Red');
								}
								
								for($x = 0; $x<count($carrier_array); $x++)
								{
									echo($carrier_array[$x] . ', ');
								}
							?>
							</td>
						</tr>
					<?endforeach;?>
				</tbody>
			</table>
		</fieldset>
	<?endif;?>
</div>